package cn.itcast.java.stream;

import org.apache.commons.io.FileUtils;

import java.io.*;
import java.util.List;

/**
 * Author itcast
 * Date 2021/10/12 22:20
 * Desc TODO
 */
public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("data/output/abc.txt");
        FileOutputStream fos = new FileOutputStream("data/output/cba.txt");
        /**
         * read() : 一次读取一个字符，并返回 int ， 如果读取不到返回 -1
         * read(数组) : 一次读取一个数组，并返回有效字节数，如果读取不到返回 -1
         */
        /*byte[] bts = new byte[1];
        int len = 0;
        while ((len = fis.read(bts)) != -1) {
//            System.out.print(new String(bts, 0, len));
            fos.write(bts);
        }*/


        BufferedInputStream bis = new BufferedInputStream(fis);
        byte[] bts = new byte[1];
        int len = 0;
        while ((len = bis.read(bts)) != -1) {
            System.out.print(new String(bts, 0, len));
//            fos.write(bts);
        }


        /*List<String> strings = FileUtils.readLines(new File("data/output/abc.txt"));
        for (String string : strings) {
            System.out.println(string);
        }*/

    }
}
